// RC_Dynust.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "ABMS_ROUTE_CHOICE_CDLL.h"
#include <iostream>
#include <fstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	/*
	int i,j,k;
	int vehid,nodenum;
	//Day 1
	float *temparray; //temparray to store one line information (seperated)
	int *temproute; //temp route to store the route as one array to pass into dll
	string templine="";
    vector<string> Sep;

	//write route_list file for day 1
	ifstream route_day1_file;
	route_day1_file.open ("C:/Users/Yiheng/Projects/VASTO/Integration/Code/Day1_route.txt");
	while (!route_day1_file.eof())
	{	
		getline(route_day1_file, templine); //read line by line
		//istringstream iss(templine);
		StringProcess::split(templine,Sep,' ');  //split one line by space
		temparray = (float*) malloc((Sep.size())*sizeof(float));  //initial temparray according to line length
		for (j=0;j<Sep.size();j++)
    	temparray[j]=atof(Sep[j].c_str());
		temproute=(int*)malloc(temparray[1]*sizeof(int)); //size of the route
		for (i=0;i<temparray[1];i++)
		{
			temproute[i]=int(temparray[2+i]);
		}
		nodenum=int(temparray[1]);
		RouteChoice::ROUTE_CHOICE_CDLL_SP_DAY1(temproute,&nodenum,&temparray[0]);
	}
	//end of write route list for day 1

	//write vehicle information for day1
	ifstream vehinfo;
	vehinfo.open ("C:/Users/Yiheng/Projects/VASTO/Integration/Code/Day1.txt");
	while (!vehinfo.eof())
	{	
		getline(vehinfo, templine); //read line by line
		//istringstream iss(templine);
		StringProcess::split(templine,Sep,' ');  //split one line by space
		temparray = (float*) malloc((Sep.size()+1)*sizeof(float));  //initial temparray according to line length
		for (j=0;j<Sep.size();j++)
    	temparray[j]=atof(Sep[j].c_str());
	    temproute=(int*)malloc(temparray[1]*sizeof(int));
		for (i=0;i<temparray[1];i++)
		{
			temproute[i]=int(temparray[4+i]);
		}
		vehid=int(temparray[0]);
		nodenum=int(temparray[1]);
		//call dll function: all other functions are executed in the dell
		RouteChoice::ROUTE_CHOICE_CDLL_FIRST_DAY_VEH(&vehid,&temparray[2],&temparray[3],temproute,&nodenum);
	}
	//end of write vehicle infomration of first day!

	//From Day 2
	//write route_list file for day 2 and update vehicle information for day 2
	ifstream route_day2_file;
	route_day2_file.open ("C:/Users/Yiheng/Projects/VASTO/Integration/Code/Day2_newroute.txt");
	while (!route_day2_file.eof())
	{	
		getline(route_day2_file, templine); //read line by line
		//istringstream iss(templine);
		StringProcess::split(templine,Sep,' ');  //split one line by space
		temparray = (float*) malloc((Sep.size())*sizeof(float));  //initial temparray according to line length
		for (j=0;j<Sep.size();j++)
    	temparray[j]=atof(Sep[j].c_str());
		temproute=(int*)malloc(temparray[4]*sizeof(int)); //decide size of the route
		for (i=0;i<temparray[4];i++)
		{
			temproute[i]=int(temparray[5+i]);    //the route start from 6th column
		}
		nodenum=int(temparray[4]);      
		//route array, number of nodes in array, departure time and travel time
		RouteChoice::ROUTE_CHOICE_CDLL_SP_DAY2(temproute,&nodenum,&temparray[2],&temparray[3]);
	}
	route_day2_file.close();

	//Read vehicle new travel times and make route choice
	ifstream veh_day2_file;
	veh_day2_file.open ("C:/Users/Yiheng/Projects/VASTO/Integration/Code/Day2_TT.txt");
	while (!veh_day2_file.eof())
	{	
		getline(veh_day2_file, templine); //read line by line
		//istringstream iss(templine);
		StringProcess::split(templine,Sep,' ');  //split one line by space
		temparray = (float*) malloc((Sep.size())*sizeof(float));  //initial temparray according to line length
		for (j=0;j<Sep.size();j++)
    	temparray[j]=atof(Sep[j].c_str());
		int id=int(temparray[0]);
		RouteChoice::ROUTE_CHOICE_CDLL_VEH(&id,&temparray[1],&temparray[2]);
	}
	//Write mpcth file
	RouteChoice::WRITE_TO_MPCTH();

	//RouteChoice::ROUTE_CHOICE_CDLL_FIRST_DAY_VEH(&a,&b,c,&d);
	//RouteChoice::ROUTE_CHOICE_CDLL_VEH(&a, &b);
*/
/*	int route[5]={1,2,3,4,5};
	int map[1]={0};
	int iteration=1;
	int VehID=1;
	float depart=1;
	float arrival=10;
	int length=5;
	int size=1;
	//RouteChoice::ROUTE_CHOICE_CDLL_VEH(&iteration,&VehID,&depart,&arrival,&length,route);
	float bbb= floor(27.5/5.0);
	RouteChoice::WRITE_TO_MTCPH(map,&size); */
	int i,j,k;
	int vehid,nodenum;
	int iteration;
	int id;
	float detime;
	float arrtime;
	int temparray[100]; //temparray to store one line information (seperated)

	int map[2]={0,1};
	k=2;
	float simtime=180;
	int agg=50;
	int vehsize=3056;
	//write route_list file for day 1
	RouteChoice::ROUTE_CHOICE_CDLL_VEHNUM(&vehsize,&simtime,&agg);

	ifstream route_day1_file;
	route_day1_file.open ("veh.dat");
	while (!route_day1_file.eof())
	{	
		route_day1_file>>iteration;
		route_day1_file>>id;
		route_day1_file>>detime;
		route_day1_file>>arrtime;
		route_day1_file>>nodenum;
		for (i=0;i<nodenum;i++)
		{
			route_day1_file>>temparray[i];
		}
		RouteChoice::ROUTE_CHOICE_CDLL_VEH_FIRSTDAY(&id,&detime,&arrtime,&nodenum,temparray);

	}
		RouteChoice::WRITE_TO_MTCPH();
	return 0;
}

